﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace PerpheralDevice.Units;
/// <summary>
/// 运动控制卡的运动轴
/// </summary>
public abstract class Motor : PerpDevUnit {
    /// <summary>
    /// 指令脉冲位置(矢量)
    /// </summary>
    public abstract int PosCommand { get; }
    /// <summary>
    /// 编码器脉冲位置(矢量)
    /// </summary>
    public abstract int PosEncoder { get; }

    #region 伺服应用操作

    /// <summary>
    /// 前往一个绝对位置
    /// </summary>
    /// <param name="posDst">绝对位置</param>
    /// <returns></returns>
    public abstract Motor ReachAbs(int posDst);
    /// <summary>
    /// 前往一个相对位置
    /// </summary>
    /// <param name="posDst">相对位置</param>
    /// <returns></returns>
    public abstract Motor ReachRel(int posDst);

    /// <summary>
    /// 回零
    /// </summary>
    /// <returns></returns>
    public abstract Motor Reset();

    /// <summary>
    /// 进行连续运动，需要主动Stop才能停止
    /// </summary>
    /// <param name="isDirReversed"></param>
    /// <returns></returns>
    public abstract Motor DoMoving();

    /// <summary>
    /// 正常停止(减速停止)
    /// </summary>
    /// <returns></returns>
    public abstract Motor Stop();
    /// <summary>
    /// 紧急停止(立即停止)
    /// </summary>
    /// <returns></returns>
    public abstract Motor Scram();
    /// <summary>
    /// 使能开启
    /// </summary>
    /// <returns></returns>
    public abstract Motor ServoEnable();
    /// <summary>
    /// 使能关闭
    /// </summary>
    /// <returns></returns>
    public abstract Motor ServoDisable();
    #endregion

    #region 伺服速度属性

    /// <summary>
    /// 伺服启动速度(矢量)
    /// </summary>
    public abstract int VelBoot { get; }
    public abstract Motor VelBootSet(int velBoot);

    /// <summary>
    /// 伺服运行速度(最大速度)(矢量)
    /// </summary>
    public abstract int VelWork { get; }
    public abstract Motor VelWorkSet(int velWork);

    /// <summary>
    /// 伺服停止速度
    /// </summary>
    public abstract int VelStop { get; }
    public abstract Motor VelStopSet(int velStop);

    /// <summary>
    /// 伺服加速度(标量)
    /// </summary>
    public abstract int VelAcc { get; }
    public abstract Motor VelAccSet(int velAcc);

    /// <summary>
    /// 伺服减速度(标量)
    /// </summary>
    public abstract int VelDec { get; }
    public abstract Motor VelDecSet(int velDec);

    /// <summary>
    /// 伺服减速时间(标量)
    /// </summary>
    public abstract double TimeAcc { get; }
    public abstract Motor TimeAccSet(double velAcc);

    /// <summary>
    /// 伺服减速时间(标量)
    /// </summary>
    public abstract double TimeDec { get; }
    public abstract Motor TimeDecSet(double timeDec);

    /// <summary>
    /// 运动方向是否为正
    /// </summary>
    public abstract bool DirMoveIsForward { get; }
    public abstract Motor DirMoveIsForwardSet(bool isForward);

    #endregion

    /// <summary>
    /// 轴是否处于运动中(推荐 通过轴厂商的API判断 来实现)
    /// </summary>
    public abstract bool IsMoving { get; }
    /// <summary>
    /// 轴是否处于运动正常(推荐通过 检测编码器到位 来实现)
    /// </summary>
    public abstract bool IsMovedOK { get; }
    /// <summary>
    /// 运动状态/状态IO
    /// </summary>
    public abstract MotorStatus MotorStatus { get; }
    /// <summary>
    /// 运动状态
    /// </summary>
    public MotorState MotorState { get; protected set; }
}

